package com.cuicuisha.gxyp.common.exception;

import com.cuicuisha.gxyp.model.vo.common.Result;
import com.cuicuisha.gxyp.model.vo.common.ResultCodeEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * ClassName: GlobalExceptionHandler
 * Description:
 *
 * @Author 脆脆鲨
 * @Create 2024-09-10 21:42
 * @Version 1.0
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(value = Exception.class)
    public Result systemExceptionHandler(Exception exception) {
        exception.printStackTrace();
        return Result.build(exception.getMessage()) ;
//        return Result.build(null , ResultCodeEnum.SYSTEM_ERROR) ;
    }

    @ExceptionHandler(value = CustomException.class)     // 处理自定义异常
    public Result customExceptionHandler(CustomException exception) {
        exception.printStackTrace();
        return Result.build(null , exception.getResultCodeEnum()) ;
    }
}
